package cn.myframe.utils.ssh;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class SSHQueue {

	//队列大小
    public static final int QUEUE_MAX_SIZE = 10000;
    private static SSHQueue alarmMessageQueue = new SSHQueue();
    //阻塞队列
    private BlockingQueue blockingQueue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE);

    private SSHQueue() {
    }

    public static SSHQueue getInstance() {
        return alarmMessageQueue;
    }
    /**
     * 消息入队
     * @param log
     * @return
     */
    public boolean push(SSHMessage msg) {
        return this.blockingQueue.add(msg);//队列满了就抛出异常，不阻塞
    }
    /**
     * 消息出队
     * @return
     */
    public SSHMessage poll() {
    	SSHMessage result = null;
        try {
            result = (SSHMessage) this.blockingQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return result;
    }

}
